<template>
    <div style="margin-top:10px;" class="imgcontainer">
        <el-button @click="handlego" type="primary" style="margin-left:55px;margin-bottom:5px;">去看看</el-button>
         <span>右键标点,点击坐标进行配置。配置完后去查看</span>
        <div class="container-box" @click.right="handleTagert" style="margin:0 auto;">
            <!-- 底图 -->
            <img src="static/img/test.png">
            <!-- 坐标点 -->
            <div class="range" id="sign" @click.stop="handleClick">
                <div class="label">
                    <div class="value">采集</div>
                    <div class="drop"></div>
                </div>
            </div>
            <!-- 已标记图标 -->      
            <div class="range"  v-for="(item,index) in list" :key="index" :style="item" @click="handleDelete(index)">
                <div class="label">
                    <div class="value">已采</div>
                    <div class="drop" style="background:#EB8847"></div>
                </div>
            </div>                                                                                                                                                                                                                                                         
        </div>


        <el-dialog title="采集坐标点" :visible.sync="centerDialogVisible" width="30%" center>
            <el-form ref="form" :model="flag" label-width="80px">
                <el-form-item label="id:">
                    <el-input v-model="flag.id"></el-input>
                </el-form-item>
                <el-form-item label="设备名字:">
                    <el-input v-model="flag.name"></el-input>
                </el-form-item>
                <el-form-item label="设备状态:">
                   <el-select v-model="flag.className">
                      <el-option v-for="(item,index) in statusList" :key="index" :label="item.name" :value="item.value"></el-option>
                   </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleOk">确 定</el-button>
        </span>
        </el-dialog>
    </div>
</template>




<script>
    export default {
        data() {
            return {
                oldtarget: '',
                num: 0,
                centerDialogVisible: false,
                flag:{
                    id:'',
                    left:'',
                    top:'',
                    name:'',
                    className: '',
                    status: '我的'
                },
                statusList:[
                    {
                        name:'正常',
                        value:'green'
                    },
                    {
                        name:'警告',
                        value:'yellow'
                    },
                    {
                        name:'危险',
                        value:'red'
                    }
                ],
                list:[],//已经标记的数组
            }
        },
        methods: {
            // 标点
            handleTagert(e) {
                if (!this.num || this.oldtarget == e.target) {
                    var target = document.getElementsByClassName("range")
                    target[0].style.left = e.offsetX - 25 + 'px'
                    target[0].style.top = e.offsetY - 45 + 'px'
                    this.flag.left = e.offsetX - 25 + 'px'
                    this.flag.top =  e.offsetY - 45 + 'px'
                    this.oldtarget = e.target
                    this.num++
                }
            },
            //采集点
            handleClick() {
                this.centerDialogVisible = true
            },
            //确认点
            handleOk(){
                this.list.push(this.flag)
                let newList = [...this.list]
                console.log(newList)
                this.centerDialogVisible = false
                this.flag = {
                    id:'',
                    left:'',
                    top:'',
                    className: 'red',
                    status: '我的'
                }
            },
            //删除点
            handleDelete(idx){
                this.list.splice(idx,1)
            },
            handlego(){
                this.$router.push({
                    name:'Answer',
                    params:{
                        list:this.list
                    }
                })
            }
        },
    }

</script>



<style scoped>
    .imgcontainer{
       overflow:auto;
    }
    .imgcontainer::-webkit-scrollbar{
      height: 5px;
      background: #ccc;
      border-radius: 5px;
    }
    .imgcontainer::-webkit-scrollbar-thumb{
      background: rgb(136, 240, 179);
      border-radius: 5px;
    }
    .container-box {
        width: 1600px;
        height: 850px;
        overflow: hidden;
        position: relative;
        background-size: cover;
    }
    .container-box img {
        height: 100%;
        width: 100%;
        z-index: -100;
    }
    .range {
        top: 0px;
        left: 0px;
        cursor: pointer;
        z-index: 100;
        box-sizing: border-box;
        position: absolute;
        padding: 0 50px;
    }
    .label {
        position: relative;
        top: 0;
        margin-left: -40px;
        margin-bottom: 20px;
        width: 80px;
    }
    .value {
        position: absolute;
        top: 10px;
        left: -40px;
        right: 0;
        margin: 0 auto;
        text-align: center;
        font-size: 12px;
        font-weight: bold;
        color: #100F0F;
        z-index: 1;
    }
    .drop {
        background: #FFEE00;
        box-sizing: content-box;
        width: 40px;
        height: 40px;
        border-radius: 80% 0 55% 50% / 55% 0 80% 50%;
        -webkit-transform: rotateZ(135deg);
        transform: rotateZ(135deg);
    }
    .logo-list{
        position: absolute;
        top: 0;
        left: 0;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: #fff;
    }
</style>